Use sources from the lockfile
authorAlex Crichton <alex@alexcrichton.com>
Thu, 31 Jul 2014 19:18:09 +0000 (12:18 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 31 Jul 2014 19:18:49 +0000 (12:18 -0700)
The sources in the lock file contain precise information about git deps so we
want them over the non-precise versions in the source.

src/cargo/core/registry.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_generate_lockfile.rs
tests/test_cargo_compile_git_deps.rs

index 22b6beefb65ce1c9a18d055d365f3771901ae328..d737d429f52a7582d7c1a9696fcc48189caa685f 100644 (file)
@@ -22,20 +22,7 @@ pub struct PackageRegistry<'a> {
 }
 
 impl<'a> PackageRegistry<'a> {
-    pub fn new<'a>(source_ids: Vec<SourceId>,
-                   config: &'a mut Config<'a>) -> CargoResult<PackageRegistry<'a>> {
-
-        let mut reg = PackageRegistry::empty(config);
-        let source_ids = dedup(source_ids);
-
-        for id in source_ids.iter() {
-            try!(reg.load(id, false));
-        }
-
-        Ok(reg)
-    }
-
-    fn empty<'a>(config: &'a mut Config<'a>) -> PackageRegistry<'a> {
+    pub fn new<'a>(config: &'a mut Config<'a>) -> PackageRegistry<'a> {
         PackageRegistry {
             sources: SourceMap::new(),
             overrides: vec!(),
@@ -77,6 +64,13 @@ impl<'a> PackageRegistry<'a> {
         Ok(())
     }
 
+    pub fn add_sources(&mut self, ids: Vec<SourceId>) -> CargoResult<()> {
+        for id in dedup(ids).iter() {
+            try!(self.load(id, false));
+        }
+        Ok(())
+    }
+
     pub fn add_overrides(&mut self, ids: Vec<SourceId>) -> CargoResult<()> {
         for id in ids.iter() {
             try!(self.load(id, true));
index 953570ac61e5131faaedc83b686dd54801941057..96182344b8cab3db6b2c8c5f4a0832c6a4dd3909 100644 (file)
@@ -65,7 +65,6 @@ pub fn compile(manifest_path: &Path,
     let user_configs = try!(config::all_configs(os::getcwd()));
     let override_ids = try!(source_ids_from_config(&user_configs,
                                                    manifest_path.dir_path()));
-    let source_ids = package.get_source_ids();
 
     let (packages, resolve, resolve_with_overrides, sources) = {
         let lockfile = manifest_path.dir_path().join("Cargo.lock");
@@ -73,11 +72,17 @@ pub fn compile(manifest_path: &Path,
 
         let mut config = try!(Config::new(*shell, update, jobs, target.clone()));
 
-        let mut registry = try!(PackageRegistry::new(source_ids, &mut config));
+        let mut registry = PackageRegistry::new(&mut config);
 
         let resolved = match try!(load_lockfile(&lockfile, source_id)) {
-            Some(r) => r,
+            Some(r) => {
+                try!(registry.add_sources(r.iter().map(|p| {
+                    p.get_source_id().clone()
+                }).collect()));
+                r
+            }
             None => {
+                try!(registry.add_sources(package.get_source_ids()));
                 try!(resolver::resolve(package.get_package_id(),
                                        package.get_dependencies(),
                                        &mut registry))
index 03209af7ce1c947f59674adf18139b9cd64b5a2f..b792dea5fdead4bffcdcd19722f2354175110fb8 100644 (file)
@@ -28,9 +28,8 @@ pub fn generate_lockfile(manifest_path: &Path,
     let resolve = {
         let mut config = try!(Config::new(shell, update, None, None));
 
-        let mut registry =
-            try!(PackageRegistry::new(source_ids, &mut config));
-
+        let mut registry = PackageRegistry::new(&mut config);
+        try!(registry.add_sources(source_ids));
         try!(resolver::resolve(package.get_package_id(),
                                package.get_dependencies(),
                                &mut registry))
index 40cf6681590aff6db48ca535f2706d92d65940fc..060bfdf0eb9d31e4f3a81b5754910f78219d21d0 100644 (file)
@@ -1,5 +1,4 @@
-use std::io::File;
-use std::path;
+use std::io::{fs, File};
 
 use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
 use support::{cargo_dir};
@@ -553,14 +552,24 @@ test!(recompilation {
                                             FRESH, git_project.root().display(),
                                             FRESH, p.root().display())));
 
-    // Commit the changes and make sure we trigger a recompile
-    File::create(&git_project.root().join("src/bar.rs")).write_str(r#"
-        pub fn bar() { println!("hello!"); }
-    "#).assert();
+    // Commit the changes and make sure we don't trigger a recompile because the
+    // lockfile says not to change
     git_project.process("git").args(["add", "."]).exec_with_output().assert();
     git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
                .assert();
 
+    assert_that(p.process(cargo_dir().join("cargo-build")).arg("-u"),
+                execs().with_stdout(format!("{} git repository `file:{}`\n\
+                                             {} bar v0.5.0 (file:{}#[..])\n\
+                                             {} foo v0.5.0 (file:{})\n",
+                                            UPDATING, git_project.root().display(),
+                                            FRESH, git_project.root().display(),
+                                            FRESH, p.root().display())));
+
+    println!("one last time");
+
+    // Remove the lockfile and make sure that we update
+    fs::unlink(&p.root().join("Cargo.lock")).assert();
     assert_that(p.process(cargo_dir().join("cargo-build")).arg("-u"),
                 execs().with_stdout(format!("{} git repository `file:{}`\n\
                                              {} bar v0.5.0 (file:{}#[..])\n\